package com.toolkit.config;

import cn.hutool.core.lang.generator.SnowflakeGenerator;
import com.toolkit.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class SnowflakeConfig {

    @Autowired
    private RedisUtil redisUtil;

    @Bean
    public SnowflakeGenerator snowflakeGenerator(){
        Long workId = redisUtil.increment("snowflakeKey") % 32 ;
        return new SnowflakeGenerator(workId, 1);
    }
}
